package com.zhl.collection_traverse;

import java.util.ArrayList;
import java.util.Collection;
import java.util.function.Consumer;

public class CollectionDemo3 {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList<>();
        collection.add("张三");
        collection.add("李四");
        collection.add("王五");
        collection.add("赵六");
        System.out.println(collection);

        //default void forEach(Consumer<? super E> action)         结合lambda表达式遍历集合
        collection.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        //简化
        collection.forEach(s ->{System.out.println(s);});
        //再一步简化
        collection.forEach(s -> System.out.println(s));
        //进一步简化   可以使用方法引用lambda表达式
        collection.forEach(System.out::println);


    }
}
